package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.model.BasicsBody;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ShopCompanyInfo;
import com.ruoyi.system.mapper.ShopCompanyInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShopUserMapper;
import com.ruoyi.system.domain.ShopUser;
import com.ruoyi.system.service.IShopUserService;

/**
 * web用户信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-03
 */
@Service
public class ShopUserServiceImpl implements IShopUserService 
{
    @Autowired
    private ShopUserMapper shopUserMapper;
    @Autowired
    private ShopCompanyInfoMapper shopCompanyInfoMapper;

    /**
     * 查询web用户信息
     * 
     * @param userId web用户信息主键
     * @return web用户信息
     */
    @Override
    public ShopUser selectShopUserByUserId(Long userId)
    {
        return shopUserMapper.selectShopUserByUserId(userId);
    }

    //根据登录名查询用户信息
    @Override
    public ShopUser selectShopUserByUserName(String userName)
    {
        return shopUserMapper.selectShopUserByUserName(userName);
    }

    /**
     * 查询web用户信息列表
     * 
     * @param shopUser web用户信息
     * @return web用户信息
     */
    @Override
    public List<ShopUser> selectShopUserList(ShopUser shopUser)
    {
        return shopUserMapper.selectShopUserList(shopUser);
    }

    /**
     * 新增web用户信息
     * 
     * @param shopUser web用户信息
     * @return 结果
     */
    @Override
    public int insertShopUser(ShopUser shopUser)
    {

        shopUser.setCreateTime(DateUtils.getNowDate());
        return shopUserMapper.insertShopUser(shopUser);
    }

    /**
     * 修改web用户信息
     * 
     * @param shopUser web用户信息
     * @return 结果
     */
    @Override
    public int updateShopUser(ShopUser shopUser)
    {
        shopUser.setUpdateTime(DateUtils.getNowDate());
        return shopUserMapper.updateShopUser(shopUser);
    }

    /**
     * 批量删除web用户信息
     * 
     * @param userIds 需要删除的web用户信息主键
     * @return 结果
     */
    @Override
    public int deleteShopUserByUserIds(Long[] userIds)
    {
        return shopUserMapper.deleteShopUserByUserIds(userIds);
    }

    /**
     * 删除web用户信息信息
     * 
     * @param userId web用户信息主键
     * @return 结果
     */
    @Override
    public int deleteShopUserByUserId(Long userId)
    {
        return shopUserMapper.deleteShopUserByUserId(userId);
    }

    @Override
    public ShopUser getShopCompanyInfoByUserId(Long userId) {
        return  shopUserMapper.getShopCompanyInfoByUserId(userId);
    }

    @Override
    public int updateCompanyAndUserInfo(BasicsBody basicsBody) {

        return shopUserMapper.updateCompanyAndUserInfo(basicsBody);
    }


    /**
     * 新增公司信息信息
     *
     * @param shopUser web用户信息对象
     */
    public void insertShopCompanyInfo(ShopUser shopUser)
    {
        List<ShopCompanyInfo> shopCompanyInfoList = shopUser.getShopCompanyInfoList();
        Long userId = shopUser.getUserId();
        if (StringUtils.isNotNull(shopCompanyInfoList))
        {
            List<ShopCompanyInfo> list = new ArrayList<ShopCompanyInfo>();
            for (ShopCompanyInfo shopCompanyInfo : shopCompanyInfoList)
            {
                shopCompanyInfo.setCompanyId(userId);
                list.add(shopCompanyInfo);
            }
            if (list.size() > 0)
            {
                shopUserMapper.batchShopCompanyInfo(list);
            }
        }
    }
}
